package com.ruoyi.teaching.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.teaching.bo.ExamRecordBo;
import com.ruoyi.teaching.domain.ExamDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.teaching.domain.ExamRecord;
import com.ruoyi.teaching.service.IExamRecordService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 学生成绩记录Controller
 *
 * @author ruoyi
 * @date 2024-04-01
 */
@RestController
@RequestMapping("/examrecord")
public class ExamRecordController extends BaseController
{
    @Autowired
    private IExamRecordService examRecordService;

    /**
     * week/last?classesId=1&stage=1
     * 根据班级id&阶段查询最后测试周数
     */
    @RequiresPermissions("teaching:examrecord:query")
    @GetMapping("/week/last")
    public AjaxResult queryLastWeek(@RequestParam("classesId") Long classesId,@RequestParam("stage") Integer stage)
    {
        return AjaxResult.success(examRecordService.selectLastWeek(classesId,stage));
    }


    /**
     * 根据班级id查询学生成绩记录详情
     */
    @RequiresPermissions("teaching:examrecord:detaillist")
    @GetMapping("/detail")
    public TableDataInfo detail(@RequestParam("classesId") Long classesId)
    {
        List<ExamDetail> list = examRecordService.selectExamDetailList(classesId);
        return getDataTable(list);
    }

    /**
     * 查询学生成绩记录列表
     */
    @RequiresPermissions("teaching:examrecord:list")
    @GetMapping("/list")
    public TableDataInfo list(ExamRecord examRecord)
    {
        startPage();
        List<ExamRecord> list = examRecordService.selectExamRecordList(examRecord);
        return getDataTable(list);
    }

    /**
     * 导出学生成绩记录列表
     */
    @RequiresPermissions("teaching:examrecord:export")
    @Log(title = "学生成绩记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamRecord examRecord)
    {
        List<ExamRecord> list = examRecordService.selectExamRecordList(examRecord);
        ExcelUtil<ExamRecord> util = new ExcelUtil<ExamRecord>(ExamRecord.class);
        util.exportExcel(response, list, "学生成绩记录数据");
    }

    /**
     * 获取学生成绩记录详细信息
     */
    @RequiresPermissions("teaching:examrecord:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(examRecordService.selectExamRecordById(id));
    }

    /**
     * 新增学生成绩记录
     */
    @RequiresPermissions("teaching:examrecord:add")
    @Log(title = "学生成绩记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamRecordBo insertExamRecordBo)
    {
        return toAjax(examRecordService.insertExamRecord(insertExamRecordBo));
    }

    /**
     * 修改学生成绩记录
     */
    @RequiresPermissions("teaching:examrecord:edit")
    @Log(title = "学生成绩记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamRecord examRecord)
    {
        return toAjax(examRecordService.updateExamRecord(examRecord));
    }

    /**
     * 删除学生成绩记录
     */
    @RequiresPermissions("teaching:examrecord:remove")
    @Log(title = "学生成绩记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(examRecordService.deleteExamRecordByIds(ids));
    }
}
